<template>
  <el-form :model="editForm" label-width="120px" :rules="editFormRules" ref="editForm">
    <el-row>
      <el-col :span="16">
        <el-form-item label="选择对应班级:" prop="class_id">
          <component
              v-bind:is="item.propertyType"
              :property.sync="item"
              v-for="(item, index) in getPower"
              :key="index"
              @updateVal="updateVal"
          ></component>
        </el-form-item>
      </el-col>
    </el-row>
    <el-form-item label="模版导出:">
      <downexcel type="studentModle" v-if="editForm.class_id" :option="editForm"></downexcel>
      <el-button size="small" v-else disabled>班级学生信息模版导出</el-button>
    </el-form-item>
    <div style="padding:0 20px">
      <el-link type="primary">注：导出特地班级学生信息模版</el-link>
    </div>
  </el-form>
</template>

<script>

export default {
  props: [], // commoent 学生点评 collection 学生采集
  components: {},
  data() {
    return {
      editForm: {
        class_id: '', // 班级id
        section_id: '', // 年段id
      }, // 编辑界面数据
      editFormRules: {
        class_id: [
          {required: true, message: '请选择年段班级', trigger: 'blur'}
        ]
      }, // 表单验证不能为空规则
      getPower: {
        'section_id': {
          name: 'section_id', // key名称
          default: '', // 默认值
          propertyType: "Select", // 组件名称
          placeholder: '班级', // 默认值
          valueText: '', // 值
          leve: 2,
          api: this.api.user_sectionindex, // 下拉框的请求接口
          keyName: 'section_name',// 调用的字段
          child: [
            {
              name: 'class_id',
              default: '',
              propertyType: "",
              placeholder: '班级',
              valueText: '',
              api: this.api.user_classesindex,
              keyName: 'class_name',
            }
          ]
        }
      },
    }
  },
  watch: {
  },
  created() {
  },
  methods: {
    // 更新值
    updateVal(option) {
      // console.log('变更数据收到的数据内容：', option)
      if (option.input) {
        this.editForm[option['input'].name] = option['input'].valueText
      } else if (option.select) {
        for (let i in option.select) {
          if (option.select[i].name) {
            this.editForm[option.select[i].name] = option.select[i].valueText
          } else {
            this.editForm[option.select[i - 1].name] = option.select[i].valueText ? option.select[i].valueText : option.select[i - 1].valueText
          }
        }
      }
    },
  },
  mounted() {
  }
}
</script>
<style scoped>
</style>


